SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[paObtenerPasoActual] 

@Tramite INT

AS
SET NOCOUNT ON
SELECT TOP 1 P.IdPaso, P.Descripcion, P.TipoDePaso, P.StoreProcedure
FROM tb_Tracking TT
INNER JOIN tb_Pasos P ON P.Tarea = TT.Tarea
WHERE Tramite = @Tramite AND TT.Estado = 4 AND 
NOT EXISTS(SELECT * FROM tb_TrackingDePasos TP WHERE TP.Tracking = TT.IdTracking AND P.IdPaso = TP.Paso)
ORDER BY NroOrdenEnTarea
GO
GRANT EXECUTE ON  [dbo].[paObtenerPasoActual] TO [GestionDeDocumentos]
GRANT EXECUTE ON  [dbo].[paObtenerPasoActual] TO [SoloVer]
GO
